use std::time::Duration;

use tokio::{sync::watch, time::sleep};

#[tokio::test]
async fn test_watch_channel() {
    let (tx, mut rx) = watch::channel("hello");

    tokio::spawn(async move {
        loop {
            println!("\n[UPDATED] {}!", *rx.borrow_and_update());
            if rx.changed().await.is_err() {
                println!("rx.changed() failed");
                break;
            }
        }
    });

    sleep(Duration::from_millis(100)).await;
    tx.send("world").unwrap();

    sleep(Duration::from_secs(1)).await;
}
